package com.partner.action.order;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.mysql.fabric.xmlrpc.base.Array;
import com.partner.bean.order.Order;
import com.partner.bean.order.Ordermi;
import com.partner.bean.withdraw.Withdraw;
import com.partner.frame.common.CommonInstans;
import com.partner.service.order.OrderService;
import com.partner.service.order.OrdermiService;
import com.partner.service.withdraw.WithdrawService;

@Controller
@RequestMapping("/order")
public class OrderAction {
	
	@Autowired
	private OrderService orderService;
	@Autowired
	private WithdrawService withdrawService;
	@Autowired
	private OrdermiService ordermiService;
	
	@RequestMapping(value = "/list")
	public ModelAndView list(HttpServletRequest request,Order order
			) throws ParseException{
		ModelAndView result = new ModelAndView();
		List<Order> orderList = orderService.selectAll(order);
		result.addObject("order", order);
		result.addObject("orderList", orderList);
		result.setViewName("/pages/order/list");
		return result;
	}
	
	@RequestMapping(value = "/list1")
	public ModelAndView list1(HttpServletRequest request,Integer id
			) throws ParseException{
		ModelAndView result = new ModelAndView();
		List<Withdraw> list = new ArrayList<>();
		Withdraw withdraw = withdrawService.selectByPrimaryId(id);
		Withdraw withdraw1 = withdrawService.selectByPrimaryId(id);
		if(withdraw!=null && withdraw.getStatus()>0 && withdraw.getStatus() < 3){	//	一级审核
			withdraw.setName("一级审核");
			list.add(withdraw);
			result.addObject("list", list);
		}else if(withdraw!=null && withdraw.getStatus()>2){
			Withdraw w1 = withdraw1;
			w1.setStatus(1);
			w1.setName("一级审核");
			withdraw.setContent(withdraw.getFinalcontent());
			withdraw.setName("财务审核");
			withdraw.setCreatetime(withdraw.getCasetime());
			list.add(w1);
			list.add(withdraw);
			result.addObject("list", list);
		}
		result.setViewName("/pages/order/list1");
		return result;
	}
	
	@RequestMapping(value = "/report1")
	public ModelAndView report1(HttpServletRequest request,Order order) throws ParseException{
		ModelAndView result = new ModelAndView();
		Integer order1 = orderService.report1(order);//收入总和
		Withdraw w1 = new Withdraw();
		w1.setStarttime(order.getStarttime());
		w1.setEndtime(order.getEndtime());
		Integer withdrar = withdrawService.report1(w1);//提现总和
		result.addObject("order1", order1);
		result.addObject("order", order);
		result.addObject("withdrar", withdrar);
		result.setViewName("/pages/report/report1");
		return result;
	}
	
	@RequestMapping(value = "/report2")
	public ModelAndView report2(HttpServletRequest request,Ordermi ordermi) throws ParseException{
		ModelAndView result = new ModelAndView();
		List<Ordermi> order1 = ordermiService.report2(ordermi);//收入总和
		result.addObject("order1", order1);
		result.addObject("order", ordermi);
		result.setViewName("/pages/report/report2");
		return result;
	}
	
	@RequestMapping(value = "/report3")
	public ModelAndView report3(HttpServletRequest request,Order order) throws ParseException{
		ModelAndView result = new ModelAndView();
		List<Order> order1 = orderService.report3(order);//收入总和
		result.addObject("order1", order1);
		result.addObject("order", order);
		result.setViewName("/pages/report/report3");
		return result;
	}
}
